/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.quality4spl.fm.cvm.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EcoreUtil;

import org.quality4spl.fm.cvm.CvmPackage;
import org.quality4spl.fm.cvm.StringConstrainingType;
import org.quality4spl.fm.cvm.UserAttributeType;
import org.quality4spl.fm.cvm.UserAttributeTypeContext;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>User Attribute Type</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.quality4spl.fm.cvm.impl.UserAttributeTypeImpl#getKey <em>Key</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.UserAttributeTypeImpl#getValidFor <em>Valid For</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.UserAttributeTypeImpl#getDescription <em>Description</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.UserAttributeTypeImpl#getContext <em>Context</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.UserAttributeTypeImpl#getType <em>Type</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class UserAttributeTypeImpl extends CVMElementImpl implements UserAttributeType {
	/**
	 * The default value of the '{@link #getKey() <em>Key</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getKey()
	 * @generated
	 * @ordered
	 */
	protected static final String KEY_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getKey() <em>Key</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getKey()
	 * @generated
	 * @ordered
	 */
	protected String key = KEY_EDEFAULT;

	/**
	 * The default value of the '{@link #getValidFor() <em>Valid For</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getValidFor()
	 * @generated
	 * @ordered
	 */
	protected static final String VALID_FOR_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getValidFor() <em>Valid For</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getValidFor()
	 * @generated
	 * @ordered
	 */
	protected String validFor = VALID_FOR_EDEFAULT;

	/**
	 * The default value of the '{@link #getDescription() <em>Description</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDescription()
	 * @generated
	 * @ordered
	 */
	protected static final String DESCRIPTION_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getDescription() <em>Description</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDescription()
	 * @generated
	 * @ordered
	 */
	protected String description = DESCRIPTION_EDEFAULT;

	/**
	 * The cached value of the '{@link #getType() <em>Type</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected StringConstrainingType type;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected UserAttributeTypeImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CvmPackage.Literals.USER_ATTRIBUTE_TYPE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getKey() {
		return key;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setKey(String newKey) {
		String oldKey = key;
		key = newKey;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.USER_ATTRIBUTE_TYPE__KEY, oldKey, key));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getValidFor() {
		return validFor;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setValidFor(String newValidFor) {
		String oldValidFor = validFor;
		validFor = newValidFor;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.USER_ATTRIBUTE_TYPE__VALID_FOR, oldValidFor, validFor));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDescription(String newDescription) {
		String oldDescription = description;
		description = newDescription;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.USER_ATTRIBUTE_TYPE__DESCRIPTION, oldDescription, description));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public UserAttributeTypeContext getContext() {
		if (eContainerFeatureID() != CvmPackage.USER_ATTRIBUTE_TYPE__CONTEXT) return null;
		return (UserAttributeTypeContext)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetContext(UserAttributeTypeContext newContext, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newContext, CvmPackage.USER_ATTRIBUTE_TYPE__CONTEXT, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setContext(UserAttributeTypeContext newContext) {
		if (newContext != eInternalContainer() || (eContainerFeatureID() != CvmPackage.USER_ATTRIBUTE_TYPE__CONTEXT && newContext != null)) {
			if (EcoreUtil.isAncestor(this, newContext))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newContext != null)
				msgs = ((InternalEObject)newContext).eInverseAdd(this, CvmPackage.USER_ATTRIBUTE_TYPE_CONTEXT__USER_ATTRIBUTE_TYPES, UserAttributeTypeContext.class, msgs);
			msgs = basicSetContext(newContext, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.USER_ATTRIBUTE_TYPE__CONTEXT, newContext, newContext));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public StringConstrainingType getType() {
		return type;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetType(StringConstrainingType newType, NotificationChain msgs) {
		StringConstrainingType oldType = type;
		type = newType;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, CvmPackage.USER_ATTRIBUTE_TYPE__TYPE, oldType, newType);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setType(StringConstrainingType newType) {
		if (newType != type) {
			NotificationChain msgs = null;
			if (type != null)
				msgs = ((InternalEObject)type).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - CvmPackage.USER_ATTRIBUTE_TYPE__TYPE, null, msgs);
			if (newType != null)
				msgs = ((InternalEObject)newType).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - CvmPackage.USER_ATTRIBUTE_TYPE__TYPE, null, msgs);
			msgs = basicSetType(newType, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.USER_ATTRIBUTE_TYPE__TYPE, newType, newType));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CvmPackage.USER_ATTRIBUTE_TYPE__CONTEXT:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetContext((UserAttributeTypeContext)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CvmPackage.USER_ATTRIBUTE_TYPE__CONTEXT:
				return basicSetContext(null, msgs);
			case CvmPackage.USER_ATTRIBUTE_TYPE__TYPE:
				return basicSetType(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case CvmPackage.USER_ATTRIBUTE_TYPE__CONTEXT:
				return eInternalContainer().eInverseRemove(this, CvmPackage.USER_ATTRIBUTE_TYPE_CONTEXT__USER_ATTRIBUTE_TYPES, UserAttributeTypeContext.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case CvmPackage.USER_ATTRIBUTE_TYPE__KEY:
				return getKey();
			case CvmPackage.USER_ATTRIBUTE_TYPE__VALID_FOR:
				return getValidFor();
			case CvmPackage.USER_ATTRIBUTE_TYPE__DESCRIPTION:
				return getDescription();
			case CvmPackage.USER_ATTRIBUTE_TYPE__CONTEXT:
				return getContext();
			case CvmPackage.USER_ATTRIBUTE_TYPE__TYPE:
				return getType();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case CvmPackage.USER_ATTRIBUTE_TYPE__KEY:
				setKey((String)newValue);
				return;
			case CvmPackage.USER_ATTRIBUTE_TYPE__VALID_FOR:
				setValidFor((String)newValue);
				return;
			case CvmPackage.USER_ATTRIBUTE_TYPE__DESCRIPTION:
				setDescription((String)newValue);
				return;
			case CvmPackage.USER_ATTRIBUTE_TYPE__CONTEXT:
				setContext((UserAttributeTypeContext)newValue);
				return;
			case CvmPackage.USER_ATTRIBUTE_TYPE__TYPE:
				setType((StringConstrainingType)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case CvmPackage.USER_ATTRIBUTE_TYPE__KEY:
				setKey(KEY_EDEFAULT);
				return;
			case CvmPackage.USER_ATTRIBUTE_TYPE__VALID_FOR:
				setValidFor(VALID_FOR_EDEFAULT);
				return;
			case CvmPackage.USER_ATTRIBUTE_TYPE__DESCRIPTION:
				setDescription(DESCRIPTION_EDEFAULT);
				return;
			case CvmPackage.USER_ATTRIBUTE_TYPE__CONTEXT:
				setContext((UserAttributeTypeContext)null);
				return;
			case CvmPackage.USER_ATTRIBUTE_TYPE__TYPE:
				setType((StringConstrainingType)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case CvmPackage.USER_ATTRIBUTE_TYPE__KEY:
				return KEY_EDEFAULT == null ? key != null : !KEY_EDEFAULT.equals(key);
			case CvmPackage.USER_ATTRIBUTE_TYPE__VALID_FOR:
				return VALID_FOR_EDEFAULT == null ? validFor != null : !VALID_FOR_EDEFAULT.equals(validFor);
			case CvmPackage.USER_ATTRIBUTE_TYPE__DESCRIPTION:
				return DESCRIPTION_EDEFAULT == null ? description != null : !DESCRIPTION_EDEFAULT.equals(description);
			case CvmPackage.USER_ATTRIBUTE_TYPE__CONTEXT:
				return getContext() != null;
			case CvmPackage.USER_ATTRIBUTE_TYPE__TYPE:
				return type != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (key: ");
		result.append(key);
		result.append(", validFor: ");
		result.append(validFor);
		result.append(", description: ");
		result.append(description);
		result.append(')');
		return result.toString();
	}

} //UserAttributeTypeImpl
